package com.cskaoyan.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Handler方法的返回值都是ModelAndView
 * @author stone
 * @date 2022/09/01 17:12
 */
@Controller
public class ModelAndViewController {

    @RequestMapping("mv1")
    public ModelAndView mv1() {
        ModelAndView modelAndView = new ModelAndView();
        // model做的事情就是给视图文件中的key提供值的
        modelAndView.addObject("email", "songge@cskaoyan.com");
        modelAndView.setViewName("/hello.jsp");
        return modelAndView;
    }

    @RequestMapping("mv2")
    public String mv2(Model model) {
        model.addAttribute("email", "ligenli@cskaoyan.com");
        return "/hello.jsp";
    }
}
